home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: David Byrden <100101.2547@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: To find the class of an object ??
- Date: 27 Feb 1996 21:54:13 GMT
- Organization: self-employed
- Message-ID: <4gvui5$fqs@news.bridge.net>
- References: <4gvel6$4vg@cf01>
- NNTP-Posting-Host: ppp-mia2-86.bridge.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
- Didier;
-
-
- >>>>
- >I have a class A and a class B. The class B inherit the class A.
- >I have too: A tab[MAX];
- >In tab, I put objets of class A or B.
-
- >How compare two objects of tab to know if they are of the same class ??
- >and which class they belong to ??
- <<<<<
-
-
-
- There is no need to compare, I can answer the question already. All the
- objects in "tab" are always of class A.
-
- When you assign a B to an A, the derived B objects gets "sliced" and
- you lose the parts that were added in class B. Only the data members of
- its base part will be assigned to the A.
-
- In a good design, a base class object has no knowlege of whether it is
- alone or whether it is part of a derived class object, so there will be
- no evidence that the assigned value was ever a B.
-
- What you probably want is for "tab" to be an array of _pointers_ to A.
-
- David
-
-
-
-